package com.ladlee.parking.pay.v3.config;

import com.ladlee.parking.pay.v3.core.PayV3Manager;
import com.ladlee.parking.pay.v3.service.PayService;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 支付自动配置
 */
@Configuration
public class PayAutoConfiguration {

    /**
     * 支付类型的数组
     */
    private final PayService[] payServices;

    private final ApplicationContext applicationContext;

    public PayAutoConfiguration(ObjectProvider<PayService[]> payServicesProvider, ApplicationContext applicationContext) {
        this.payServices = payServicesProvider.getIfAvailable();
        this.applicationContext = applicationContext;
    }

    @Bean
    public PayV3Manager payV3Manager() {
        return new PayV3Manager(payServices);
    }
}
